package com.stx.day0922;

/**
 * packageName com.stx.day0922
 *
 * @author YangYi
 * @className ExceptionDemo
 * @date 2025/9/22
 * @description TODO
 */
public class ExceptionDemo {
    public static void main(String[] args) {
        int a = 10;
        int b = 0;
        try{
            if(b <= 0){
                throw new NewArithmeticException("除数不能为0");
            }
            // 除数不能为零异常
            System.out.println(a / b);
            // 下标越界异常
//            int[] array = {1,2,3};
//            System.out.println(array[5]);
        }catch (ArithmeticException e){
            System.out.println("by zero");
            // 方法题里面进行抛出异常
            throw e;
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("下标越界异常");
            throw e;
        }finally {
            // 最后都会执行这里面的代码
            System.out.println("finally执行了....");
        }
    }
}
